import React, { useEffect, useState } from "react";
import type {Node} from 'react';

import {Provider} from 'react-redux';
import play from './src/redux/reducer/music-play';
import {createStore} from 'redux';
import HomePage from "./src/component/HomePage/HomePage";
import Video from "react-native-video";
import { NativeModules, StyleSheet } from "react-native";
import Play from "./src/component/Play";
import LinkMusicPlayer from "./src/component/MusicPlayer/LinkMusicPlayer";
import LinkPlay from "./src/component/LinkPlay";
import LinkBottomPlayBar from "./src/component/BottomPlayBar/LinkBottomPlayBar";
import AllPlayList from "./src/component/AllPlayList/AllPlayList";

import { NavigationContainer } from "@react-navigation/native";
import { createNativeStackNavigator } from "@react-navigation/native-stack";
import PickerCat from "./src/component/AllPlayList/PickerCat";
import { List } from "@ant-design/react-native";
import ListDetail from "./src/component/ListDetail/ListDetail";
import SearchPage from "./src/component/SearchPage/SearchPage";
import LinkSearchPage from "./src/component/SearchPage/LinkSearchPage";
import LinkListDetail from "./src/component/ListDetail/LinkListDetail";
import LoginPage from "./src/component/LoginPage/LoginPage";
import LoginNetease from "./src/component/LoginPage/LoginNetease";
import { INIT_STATE } from "./src/redux/action";
import LocalPlayList from "./src/component/LocalPlayList/LocalPlayList";
import LocalListDetail from "./src/component/LocalPlayList/LocalListDetail";
import LinkLocalListDetail from "./src/component/LocalPlayList/LinkLocalListDetail";
import LinkLocalPlayList from "./src/component/LocalPlayList/LinkLocalPlayList";
const App: () => Node = () => {

  //后期从本地缓存获取
  let [initData,setInitData] = useState({
    play:false,
    currentMusic:{},
    currentTime:0,
    musicList:[],
    duration:0,
    isPressed:false,
    player:{},
    seeked:true,
    playControlBottom:true
  });
  let store = createStore(play,initData);

  const Stack = createNativeStackNavigator();

  useEffect(() => {
    //console.log('加载local');
    initState()

  },[])
  function initState(){
    NativeModules.ToolModule.getState().then((r) => {
      let s = JSON.parse(r.state);
      let data = {
        play: false,
        currentTime: 0,
        duration: 0,
        isPressed: false,
        player: {},
        seeked: true,
        playControlBottom: true,
        currentMusic: s.currentMusic || {},
        musicList: s.musicList || [],
        toAdd:false,
        toAddValue:""
      }
      store.dispatch(INIT_STATE(data))
    })
  }
  return (
    <Provider store={store}>
      <NavigationContainer>
        <Stack.Navigator initialRouteName="Home"  style={{marginBottom:55}}>
          <Stack.Screen name='Home' component={HomePage}options={{headerShown:false}}/>
          <Stack.Screen name='AllPlayList' component={AllPlayList} options={{headerShown:false}}/>
          <Stack.Screen name='MusicPlayer' component={LinkMusicPlayer} options={{headerShown:false}}/>
          <Stack.Screen name='PickerCat' component={PickerCat} options={{headerShown:false}}/>
          <Stack.Screen name='ListDetail' component={LinkListDetail} options={{headerShown:false}}/>
          <Stack.Screen name='SearchPage' component={LinkSearchPage} options={{headerShown:false}}/>
          <Stack.Screen name='LoginPage' component={LoginPage} options={{headerShown:false}}/>
          <Stack.Screen name='LoginNetease' component={LoginNetease} options={{headerShown:false}}/>
          <Stack.Screen name='LocalList' component={LinkLocalPlayList} options={{headerShown:false}}/>
          <Stack.Screen name='LocalListDetail' component={LinkLocalListDetail} options={{headerShown:false}}/>
        </Stack.Navigator>

        <LinkBottomPlayBar/>
        <LinkPlay/>

      </NavigationContainer>
    </Provider>
  );
};

export default App;
